#include "threadPool.h"
int func_gets(int netfd,char * target_path,stringStack_t * stack) {
    train_t train;
    char filename[4096] = {0};
    strcat(filename,target_path);
    recvn(netfd, &train.length, sizeof(train.length));
    recvn(netfd, train.data, train.length);
    int fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666);

    off_t filesize=0;
    recvn(netfd, &train.length, sizeof(train.length));
    recvn(netfd, train.data, train.length);
    printf("filesize = %s\n", train.data);
    int hh=atoi(train.data);
    filesize=hh;
    off_t cursize = 0;
    off_t lastsize = 0;
    off_t slice = filesize/10000;
    while(1) {
        recvn(netfd, &train.length, sizeof(train.length));
        if(train.length == 0) {
            break;


        }
        cursize += train.length;
        if(cursize - lastsize > slice) {
            printf("%5.2lf%%\r", 100.0*cursize/filesize);
            fflush(stdout);
            lastsize = cursize;


        }
        recvn(netfd, train.data, train.length);
        write(fd, train.data, train.length);


    }
    printf("100.00%%\n");
    close(fd);
    return 0;


}
